﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WD.Shell
{
    public class MainWindowPresenter:DependencyObject
    {
        private ResourceDictionary Dictionary { get; set; }
        public ICommand ApplyThemeCommand { get; set; }
        public ICommand ChangeCenter { get; set; }

            
        public MainWindowPresenter(Canvas graphControl)
        {
            _graphControl = graphControl;
            Dictionary  = new ResourceDictionary();
            ApplyThemeCommand = new DelegateCommand(OnApplyThemeCommand, CanApplyThemeCommand);
            ChangeCenter = new DelegateCommand(OnChangeCenterCommand, CanChangeCenterCommand);
        }

        private bool CanChangeCenterCommand(object parameter)
        {
            return true;
        }

        private void OnChangeCenterCommand(object parameter)
        {
            var direction = parameter.ToString();
            switch (direction)
            {
                case "Up":
                    CenterY -= 50;
                    break;
                case "Down":
                   CenterY += 50;
                    break;
                case "Left":
                   CenterX -= 50;
                    break;
                case "Right":
                    CenterX += 50;
                    break;
                case "Center":
                    CenterX = 0;
                    CenterY = 0;
                    break;
            }

            //_graphControl.Margin = new Thickness(CenterX,CenterY,0,0);
            
        }

        private bool CanApplyThemeCommand(object parameter)
        {
            return true;
        }

        private void OnApplyThemeCommand(object parameter)
        {
            var themeName = parameter as string;
            var uriString = string.Format("/WD.Shell;component/Theme/{0}/Theme.xaml",themeName);
            Dictionary.Source = new Uri(uriString, UriKind.Relative);
            Application.Current.Resources.MergedDictionaries.Clear();
            Application.Current.Resources.MergedDictionaries.Add(Dictionary);
        }


        public double CenterX
        {
            get { return (double)GetValue(CenterXProperty); }
            set { SetValue(CenterXProperty, value); }
        }

        public static readonly DependencyProperty CenterXProperty =
            DependencyProperty.Register("CenterX", typeof(double), 
            typeof(MainWindowPresenter), new UIPropertyMetadata(0d));


        public double CenterY
        {
            get { return (double)GetValue(CenterYProperty); }
            set { SetValue(CenterYProperty, value); }
        }

        public static readonly DependencyProperty CenterYProperty =
            DependencyProperty.Register("CenterY", typeof(double), 
            typeof(MainWindowPresenter), new UIPropertyMetadata(0d));

        private Canvas _graphControl;
    }
}
